/*     */ package com.zimbra.cs.fb;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.AccessManager;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.User;
/*     */ import com.zimbra.cs.mailbox.Appointment;
/*     */ import com.zimbra.cs.mailbox.CalendarItem;
/*     */ import com.zimbra.cs.mailbox.Flag;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache.CalendarDataResult;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.CalendarData;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.CalendarItemData;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.FullInstanceData;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.InstanceData;
/*     */ import java.io.PrintStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class LocalFreeBusyProvider
/*     */ {
/*     */   public static FreeBusy getFreeBusyList(Account authAcct, boolean asAdmin, Mailbox mbox, String name, long start, long end, int folder, Appointment exAppt)
/*     */     throws ServiceException
/*     */   {
/*  61 */     AccessManager accessMgr = AccessManager.getInstance();
/*  62 */     boolean accountAceAllowed = accessMgr.canDo(authAcct, mbox.getAccount(), Rights.User.R_viewFreeBusy, asAdmin);
/*  63 */     int numAllowedFolders = 0;
/*     */     
/*  65 */     int exApptId = exAppt == null ? -1 : exAppt.getId();
/*     */     
/*  67 */     FreeBusy.IntervalList intervals = new FreeBusy.IntervalList(start, end);
/*     */     List<CalSummaryCache.CalendarDataResult> calDataResultList;
/*     */     List<CalSummaryCache.CalendarDataResult> calDataResultList;
/*  70 */     if (folder == -1) {
/*  71 */       calDataResultList = mbox.getAllCalendarsSummaryForRange(null, MailItem.Type.APPOINTMENT, start, end);
/*     */     } else {
/*  73 */       calDataResultList = new ArrayList(1);
/*  74 */       calDataResultList.add(mbox.getCalendarSummaryForRange(null, folder, MailItem.Type.APPOINTMENT, start, end));
/*     */     }
/*  76 */     for (CalSummaryCache.CalendarDataResult result : calDataResultList) {
/*  77 */       int folderId = result.data.getFolderId();
/*  78 */       Folder f = mbox.getFolderById(null, folderId);
/*  79 */       if ((f.getFlagBitmask() & Flag.BITMASK_EXCLUDE_FREEBUSY) != 0) {
/*  80 */         ZimbraLog.fb.debug("Calendar '%s' id=%s ignored - has EXCLUDE_FREEBUSY flag set", new Object[] { f.getName(), Integer.valueOf(folderId) });
/*     */       }
/*     */       else
/*     */       {
/*  84 */         boolean folderFBAllowed = CalendarItem.allowFreeBusyAccess(f, authAcct, asAdmin);
/*  85 */         if (folderFBAllowed)
/*  86 */           numAllowedFolders++;
/*  87 */         if ((!folderFBAllowed) && (!accountAceAllowed)) {
/*  88 */           ZimbraLog.fb.debug("Calendar '%s' id=%s ignored - folderFBAllowed=%s accountAceAllowed=%s", new Object[] { f.getName(), Integer.valueOf(folderId), Boolean.valueOf(folderFBAllowed), Boolean.valueOf(accountAceAllowed) });
/*     */         }
/*     */         else
/*     */         {
/*  92 */           for (iter = result.data.calendarItemIterator(); iter.hasNext();) {
/*  93 */             CalendarItemData appt = (CalendarItemData)iter.next();
/*  94 */             apptId = appt.getCalItemId();
/*  95 */             if (apptId != exApptId)
/*     */             {
/*  97 */               FullInstanceData defaultInstance = appt.getDefaultData();
/*  98 */               if (defaultInstance != null)
/*     */               {
/* 100 */                 isTransparent = false;
/* 101 */                 String transp = defaultInstance.getTransparency();
/* 102 */                 isTransparent = "T".equals(transp);
/* 103 */                 defaultDuration = 0L;
/* 104 */                 if (defaultInstance.getDuration() != null)
/* 105 */                   defaultDuration = defaultInstance.getDuration().longValue();
/* 106 */                 defaultFreeBusy = defaultInstance.getFreeBusyActual();
/* 107 */                 for (instIter = appt.instanceIterator(); instIter.hasNext();) {
/* 108 */                   InstanceData instance = (InstanceData)instIter.next();
/* 109 */                   long instStart = instance.getDtStart() != null ? instance.getDtStart().longValue() : 0L;
/*     */                   
/* 111 */                   if (instStart < end)
/*     */                   {
/* 113 */                     long dur = defaultDuration;
/* 114 */                     if (instance.getDuration() != null)
/* 115 */                       dur = instance.getDuration().longValue();
/* 116 */                     if (dur > 0L)
/*     */                     {
/* 118 */                       long instEnd = instStart + dur;
/*     */                       
/* 120 */                       long recurIdDt = 0L;
/*     */                       
/* 122 */                       if ((instance instanceof FullInstanceData)) {
/* 123 */                         FullInstanceData fullInst = (FullInstanceData)instance;
/* 124 */                         String transpInst = fullInst.getTransparency();
/* 125 */                         recurIdDt = fullInst.getRecurrenceId();
/* 126 */                         if ("T".equals(transpInst))
/*     */                           continue;
/* 128 */                       } else { if (isTransparent) {
/*     */                           continue;
/*     */                         }
/*     */                       }
/* 132 */                       String freeBusy = instance.getFreeBusyActual();
/* 133 */                       if (freeBusy == null)
/* 134 */                         freeBusy = defaultFreeBusy;
/* 135 */                       if (!"F".equals(freeBusy)) {
/* 136 */                         FreeBusy.FBInstance fbInst = new FreeBusy.FBInstance(freeBusy, instStart, instEnd, apptId, recurIdDt);
/* 137 */                         FreeBusy.Interval ival = new FreeBusy.Interval(instStart, instEnd, freeBusy, fbInst);
/* 138 */                         intervals.addInterval(ival); } } } } } } } } } }
/*     */     Iterator<CalendarItemData> iter;
/*     */     int apptId;
/*     */     boolean isTransparent;
/*     */     long defaultDuration;
/* 143 */     String defaultFreeBusy; Iterator<InstanceData> instIter; if ((!accountAceAllowed) && (numAllowedFolders == 0) && (!LC.freebusy_disable_nodata_status.booleanValue())) {
/* 144 */       FreeBusy.Interval nodata = new FreeBusy.Interval(start, end, "N");
/* 145 */       intervals.addInterval(nodata);
/*     */     }
/* 147 */     return new FreeBusy(name, intervals, start, end);
/*     */   }
/*     */   
/*     */   public static void main(String[] args) {
/* 151 */     FreeBusy.IntervalList l = new FreeBusy.IntervalList(0L, 100L);
/*     */     
/*     */ 
/* 154 */     System.out.println("List: " + l.toString());
/*     */     
/* 156 */     FreeBusy.Interval toAdd = new FreeBusy.Interval(50L, 60L, "B");
/* 157 */     l.addInterval(toAdd);
/* 158 */     System.out.println("Added: " + toAdd + l.toString());
/* 159 */     toAdd = new FreeBusy.Interval(10L, 20L, "T");
/* 160 */     l.addInterval(toAdd);
/* 161 */     System.out.println("Added: " + toAdd + l.toString());
/* 162 */     toAdd = new FreeBusy.Interval(20L, 30L, "O");
/* 163 */     l.addInterval(toAdd);
/* 164 */     System.out.println("Added: " + toAdd + l.toString());
/* 165 */     toAdd = new FreeBusy.Interval(15L, 35L, "B");
/* 166 */     l.addInterval(toAdd);
/* 167 */     System.out.println("Added: " + toAdd + l.toString());
/*     */     try
/*     */     {
/* 170 */       Mailbox mbox = MailboxManager.getInstance().getMailboxById(1);
/* 171 */       FreeBusy fb = getFreeBusyList(mbox.getAccount(), false, mbox, mbox.getAccount().getName(), 0L, Long.MAX_VALUE, -1, null);
/* 172 */       System.out.println(fb.toString());
/*     */     } catch (ServiceException e) {
/* 174 */       System.out.println("EXCEPTION: " + e);
/* 175 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/fb/LocalFreeBusyProvider.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */